import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    //component:pageA,
    redirect: '/login',
  },
  {
    path:'/login',
    name:'login',
    component:() => import('../views/login')
  },
  {
    path:'/category',
    name:'category',
    component:() => import('../views/category')
  },
  {
    path:'/products',
    name:'products',
    component:() => import('../views/products')
  },
  {
    path:'/product',
    name:'product',
    component:() => import('../views/product')
  },
  {
    path:'/juzao1',
    name:'juzao1',
    component:() => import('../views/juzao1')
  },
  {
    path:'/fenlei',
    name:'fenlei',
    component:() => import('../views/fenlei')
  },
  {
    path: '/index',
    component: () => import('../views/index'),
    redirect: '/index/userList',
    children: [
      //用户管理
      { path: 'userList', name: 'userList', component: () => import('../views/user/list'), meta: { title: '系统设置 / 人员管理' } },
      { path: 'userEdit', name: 'userEdit', component: () => import('../views/user/edit'), meta: { title: '系统设置 / 人员管理 / 编辑人员信息' }},
      //群组管理
      { path: 'groupList', name: 'groupList', component: () => import('../views/group/list'), meta: { title: '系统设置 / 群组管理' } },
      { path: 'groupEdit', name: 'groupEdit', component: () => import('../views/group/edit'), meta: { title: '系统设置 / 群组管理 / 编辑群组信息' }},
      //菜单管理
      { path: 'menu', name: 'menu', component: () => import('../views/menu/list'), meta: { title: '系统设置 / 菜单管理' } },
      //商品管理
      { path: 'product', name: 'product', component: () => import('../views/product/list'), meta: { title: '系统设置 / 商品管理' } },
    ]
  }
]

const router = new VueRouter({
  routes
})

const isLogin = true

router.beforeEach((to, from, next) => {
  // ...
  if (to.meta.requiresAuth && isLogin) {
    next()
  } else {
    //next({path:'/login'})
    //跳转到登录页面
    next()
  }
})

export default router